package org.blame.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何彦声
 * Date: 2025-08-27
 * Time:
 */

@RestController
@RequestMapping("/sse")
public class SseController {

    @RequestMapping("/data")
    public void data(HttpServletResponse response) throws IOException, InterruptedException {
        response.setContentType("text/event-stream;charset=utf-8");
        PrintWriter writer = response.getWriter();

        for (int i = 0; i < 20; i++) {
            String s="data:" + new Date() +"\n\n";
            writer.write(s);
            writer.flush();
            Thread.sleep(1000L);
        }

    }
}
